package d6_map_impl;

import java.util.*;

public class nestingOfCollectionsTest {
    public static void main(String[] args) {
        //目标: 掌握集合的嵌套使用-->注意在开发中很常见
        //1、定义一个集合存储全部的省份和城市的信息
        //写代码尽量利用多态
        Map<String, List<String>> provinces = new HashMap<>();

        //2、定义集合存储所有城市的信息
        List<String> cities1 = new ArrayList<>();
        //将城市存进去
        Collections.addAll(cities1, "南京市", "扬州市", "苏州市", "无锡市", "常州市");
        //压到hashMap中
        provinces.put("江苏省", cities1);
        List<String> cities2 = new ArrayList<>();
        //将该省的城市存储进去
        Collections.addAll(cities2, "武汉市", "孝感市", "十堰市", "宜昌市", "鄂州市");
        provinces.put("湖北省", cities2);

        List<String> cities3 = new ArrayList<>();
        Collections.addAll(cities3, "石家庄", "唐山市", "邢台市", "保定市", "张家口市");
        provinces.put("河北省", cities3);
        //""都存在字符串常量池中,哈希值一样
        List<String> huBei = provinces.get("湖北省");
        for (String s : huBei) {
            System.out.println(s);
        }

        //遍历provinces(省份)
        Set<Map.Entry<String, List<String>>> entries = provinces.entrySet();
        for (Map.Entry<String, List<String>> entry : entries) {
            String key = entry.getKey();
            List<String> value = entry.getValue();
            System.out.println(key + "==" + value);
        }

//        System.out.println(provinces);


    }
}
